//
//  NRWCarChooseTagView.m
//  New_Runway
//
//  Created by 邢毅 on 2018/6/1.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWCarChooseTagView.h"

@implementation NRWCarChooseTagView
{
    UIScrollView *_scrollView;
    int _baseTag;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.backgroundColor = MAIN_BACKGROUND_COLOR();
        
        _baseTag = 100;
        
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.contentInset = UIEdgeInsetsMake(0, 10, 0, -10);
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        for (NSInteger i = 0; i < [self getImagesName].count; i++) {
            
            UIButton *btn = [[UIButton alloc] init];
            btn.frame = CGRectMake(i * 70 + (i > 0? 5 * i: 0), 0, 70, 70);
            [btn setImage:getImageFromName([self getImagesName][i]) forState:UIControlStateNormal];
            btn.tag = _baseTag + i;
            [btn addTarget:self action:@selector(tagBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:btn];
        }
        
        _scrollView.contentSize = CGSizeMake(self.getImagesName.count * 70 + 20 + ([self getImagesName].count - 1) * 5, 0);
        
        [self addSubview:_scrollView];
        
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    _scrollView.frame = self.bounds;
}

- (void)tagBtnDidClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(carChooseTagView:itemBtnDidClick:aiIndex:tagImageName:)]) {
        
        [self.delegate carChooseTagView:self itemBtnDidClick:sender aiIndex:sender.tag - _baseTag tagImageName:self.getImagesName[sender.tag - _baseTag]];
    }
}

- (NSArray <NSString *>*)getImagesName {
    
    return @[@"share_canbooked", @"share_presale", @"share_specialoffer", @"share_recommend", @"share_newcar", @"share_sold"];
}

@end
